package com.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/autodeliver")
public class AutodeliverController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private RestTemplate restTemplate;
    ///autodeliver/checkState/1545132
    @GetMapping("/checkState/{userId}")
    public Integer finResumeOpenState(@PathVariable Long userId){
       /* //通过springcloud提供的客户端对象来获取服务列表
        List<ServiceInstance> instances = discoveryClient.getInstances("my-server-resume");
        ServiceInstance serviceInstance = instances.get(0);
        //获取元数据host port
        String host = serviceInstance.getHost();
        int port = serviceInstance.getPort();
        String url = "http://"+host+":"+port+"/resume/openstate/"+userId;
        System.out.println(url);
        //调用远程服务——简历微服务接口（通过RestTemplate对象）*/
        String url = "http://my-service-resume/resume/openstate/"+userId;
        System.out.println(url);

        Integer forObject = restTemplate.getForObject(url, Integer.class);
        return forObject;

    }





}
